package cn.com.yusys.yusp.admin.service.impl;

import cn.com.yusys.yusp.admin.domain.AdminSmMessage;
import cn.com.yusys.yusp.admin.service.AdminSmMessageService;
import cn.com.yusys.yusp.admin.service.MessageProviderService;
import cn.com.yusys.yusp.commons.exception.Message;
import cn.com.yusys.yusp.commons.exception.MessageConstants;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageProviderServiceImpl implements MessageProviderService {
    private static final Logger logger = LoggerFactory.getLogger(MessageProviderServiceImpl.class);

    @Autowired
    private AdminSmMessageService adminSmMessageService;

    /**
     * @方法名称: getMessage
     * @方法描述: 从service获取信息详情
     * @参数与返回说明:
     * @算法描述:
     */
    public Message getMessage(String code) {
        try {
            AdminSmMessage adminSmMessage = adminSmMessageService.getMessageInfoWithCache(code);

            Message message = new Message();
            message.setCode(adminSmMessage.getCode());
            message.setLevel(adminSmMessage.getMessageLevel());
            message.setMessage(adminSmMessage.getMessage());
            return message;
        } catch (Exception e) {
            logger.error("Get Message by code exception,errorMsg:{}", e.getMessage());
            return new Message(code, "no content", MessageConstants.MSG_LEVEL_ERROR);
        }
    }
}
